<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body{
            background-color: aqua;
        }
        #box{
            
            height: 800px;
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 80px;
            color: gray;
            text-shadow: #fff 3px 4px 5px;
            font-weight: bolder;
            flex-wrap: wrap;
            text-align: center;
            line-height: 180px;
        }
    </style>
</head>
<body>
    <div id="box">
        <span id="days"></span>
    </div>

    <script>
        // 作业：定义一个生成随机颜色的函数
        // 定义一个函数返回时间差
       function getRandomColor() {
            var r = Math.floor(Math.random() * 256);
            var g = Math.floor(Math.random() * 256);
            var b = Math.floor(Math.random() * 256);
            return "rgb(" + r + ',' + g + ',' + b + ")";
            // return '#' + Math.floor(Math.random() * 0xffffff).toString(16);
            // let max=Math.max(a,b);
            // let min=Math.min(a,b);
            // return Math.floor(Math.random() *(max-min+1)+min);
        };

        setInterval(function(){
            let days = document.querySelector("#days");//获取元素节点
            // console.log(days);
            // days.innerText = 111;//day.innerText：向元素内添加内容
            // 元素.style.color = xxxx;
            let body = document.querySelector("body");

            let time1 = new Date();//现在的时间
            let time2 = new Date("2022-9-23 20:30:00");//今年双十一

            // 相减得到时间差 相差的毫秒数
            let dTime = time2 - time1;//相差时间

            let day = dTime / (1000*60*60*24);
            // console.log(day);

            // 向下取整
            day = parseInt(day);
            // console.log(day);

            let dHours = parseInt(dTime / (1000*60*60) % 24)
            // console.log(dHours);
            let dMin = parseInt(dTime / 1000 / 60 % 60)
            // console.log(dMin);
            let second = parseInt(dTime / 1000 % 60)

            let res = `距离下课还剩
            ${day}天${dHours}时${dMin}分${second}秒`;
            days.innerText =res;
            days.style.color=getRandomColor();
            body.style.backgroundColor=getRandomColor();
        },1000);

            
           
        
       
    </script>
</body>
</html>